package main

import (
	"github.com/1141520944/go-library/hjz/common"
	"github.com/1141520944/go-library/library/log"
	"github.com/gin-gonic/gin"
	"learn/k8s/internal/api"
	"learn/k8s/internal/config"
	"learn/k8s/internal/pkg/data"
	"learn/k8s/internal/pkg/util"
	"net/http"
)

func main() {
	var (
		err  error
		conf *config.Config
		db   *data.Data
		l    *log.Logger
	)
	defer func() {
		if err != nil {
			println(err.Error())
		}
	}()
	conf, err = config.Init()
	if err != nil {
		panic(err.Error())
	}
	//println(util.JsonIndex(conf))
	l = util.InitLog(conf.Log)
	if db, err = data.InitData(conf.Data); err != nil {
		return
	}
	e := gin.Default()
	api.NewAPI(e, db, l)
	r := common.InitRouter(e, util.L())
	server := &http.Server{Addr: config.Conf().Server.Addr, Handler: r}
	common.Run(util.L(), server, nil)
}
